import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/login/Index.vue'
import Layout from '@/views/layout/Index.vue'
import Home from '@/views/home/Index.vue'
import Category from '@/views/category/Index.vue'
import SubCategory from '@/views/sub-category/Index.vue'
import Detail from '@/views/detail/Index.vue'
import CartList from '@/views/cartlist/Index.vue'
import Checkout from '@/views/checkout/Index.vue'
import Pay from '@/views/pay/Index.vue'
import PayBack from '@/views/pay/PayBack.vue'
import MemberIndex from '@/views/member/MemberIndex.vue'
import UserInfo from '@/views/member/components/UserInfo.vue'
import UserOrder from '@/views/member/components/UserOrder.vue'
import SKU from '@/SKU/SKU.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [

    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home,
        },
        {
          path: 'category/:id',
          component: Category
        },
        {
          path: 'category/sub/:id',
          component: SubCategory
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'cartlist',
          component: CartList
        },
        {
          path: 'checkout',
          component: Checkout
        },
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'payback',
          component: PayBack
        },
        {
          path: 'member',
          component: MemberIndex,

          children: [
            {
              path: '',
              redirect: 'member/user'
            },
            {
              path: 'user',
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            }
          ]
        }
      ]
    },

    {
      path: '/login',
      component: Login
    },

    {
      path: '/sku',
      component: SKU
    }
  ],
  scrollBehavior(){
    return {
      top: 0
    }
  }
})

export default router
